﻿//===================================================================================
// Copyright (c) Ryan Garrett.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===================================================================================
using System;

namespace Caffeine.Core.ModelProperty
{
    internal sealed class ValueTypeProperty<T> : ModelProperty<T> where T : struct, IEquatable<T>
    {
        public ValueTypeProperty(ModelBase parent, String name, Nullable<ModelPropertyBehaviors> behavior, Boolean isWrapped)
            : base(parent, name, behavior, isWrapped)
        {
        }

        public override String ToString()
        {
            return Value.ToString();
        }

        internal override void MergeAdjacentProperty(ModelPropertyBase property)
        {
            Value = (property as ValueTypeProperty<T>).Value;
        }

        protected override Boolean OnCompareValues(T currentValue, T newValue)
        {
            return currentValue.Equals(newValue);
        }
    }
}
